package com.mark.admin.dao;

import org.apache.ibatis.annotations.*;


import java.util.HashMap;
import java.util.List;

/**
 * @Description :
 * @Author :  Markburt
 * @CreateDate :  2020/3/7$ 下午 03:04$
 * @UpdateUser :  Markburt
 * @UpdateDate :  2020/3/7$ 下午 03:04$
 * @UpdateRemark :  Project Build
 * @Version :  1.0
 */

@Mapper
public interface CommonDao {


    /***
     * 查询列表
     * @param tableName
     * @param start
     * @param size
     * @return
     */
    @Select("select * from ${tableName} limit #{start},#{size}")
    @ResultType(HashMap.class)
    List<HashMap> list(@Param("tableName") String tableName, @Param("start") int start, @Param("size") int size);


    /***
     * 查询列表计数
     * @param tableName
     * @return
     */

    @Select("select count(*) from ${tableName}")
    @ResultType(Integer.class)
    int listCount(@Param("tableName") String tableName);


    /***
     * 查询列出位置
     * @param tableName
     * @param where
     * @param start
     * @param size
     * @return
     */

    @Select("select * from ${tableName} where 1=1 ${where} limit #{start},#{size} ")//where ==> and name = 11  and password = ddd
    @ResultType(HashMap.class)
    List<HashMap> listForWhere(@Param("tableName") String tableName,@Param("where") String where,@Param("start") int start,@Param("size") int size);


    /**
     * 列表计算位置
     * @param tableName
     * @param where
     * @return
     */
    @Select("select * from ${tableName} where 1=1 ${where} ")//where ==> and name = 11  and password = ddd
    @ResultType(Integer.class)
    int listCountForWhere(@Param("tableName") String tableName,@Param("where") String where);


    /***
     * 更新列表
     * @param tableName
     * @param where
     * @param sets
     * @return
     */
    @Update("update ${tableName} set ${sets} where 1=1 ${where}")//sets==>  name=xxx,password=xsdfd
    @ResultType(Integer.class)
    int update(@Param("tableName") String tableName,@Param("where") String where,@Param("sets") String sets);


    /**
     * 插入列表
     * @param tableName
     * @param fileds
     * @param values
     * @return
     */

    @Insert("insert into ${tableName} (${fileds}) values (${values})")
    @ResultType(Integer.class)
    int insert(@Param("tableName") String tableName,@Param("fileds") String fileds,@Param("values")String values);


    /***
     * 删除列表
     * @param tableName
     * @param where
     * @return
     */

    @Delete("delete from ${tableName} where 1 = 1 ${where} limit 1")
    @ResultType(Integer.class)
    int delete(@Param("tableName") String tableName,@Param("where") String where);
}
